import axios from "axios";
import { ElMessage } from 'element-plus'
import { fileApi } from "@/api/investment";
const onUpload = ({ url, ...data }) => {
  return axios.put(url, data.file, {
    "Content-Type": "multipart/form-data",
  });
};
const fileAddress = "http://182.148.53.132:9000/gxsst/";
export const useUpload = async ({ file, ...rest }) => {
  const formData = new FormData();
  formData.append('file', file);

  const { code, data } = await fileApi.upload(formData);
  if (code != '200'){
    return  ElMessage.error("上传失败,请联系管理员!");
  }
  // const { data } = await fileApi.getMinioAddress({ fileName: file.name });
  // const { url, fileUrl } = data;
  // await onUpload({ url, urlKey: fileUrl, file });
  return { fileUrl: fileAddress + data };
};